
/**
 * @author LKQ
 * @date 2021/12/24 22:15
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {3,0,1};
        System.out.println(solution.missingNumber(nums));
    }

    public int missingNumber(int[] nums) {
        int n = nums.length;
        // 虽然想到了异或运算，但是独立开辟了2*n+1的空间，可以不开辟
        int[] arr = new int[2*n+1];
        for (int i = 0; i < 2*n + 1; i++) {
            if (i <= n) {
                arr[i] = i;
            }else  {
                arr[i] = nums[i-n-1];
            }
        }
        int ans = 0;
        for (int k : arr) {
            ans ^= k;
        }
        return ans;
    }
}
